package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Officematerial;
import edu.hwadee.service.OfficematerialService;

public class OfficematerialServiceImpl extends BasicServiceImpl implements OfficematerialService {

	@Override
	public boolean save(Officematerial officematerial) {
		try {
			getOfficematerialDAO().save(officematerial);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Officematerial officematerial) {
		try {
			getOfficematerialDAO().delete(officematerial);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerial> search(Officematerial officematerial) {
		try {
			return (List<Officematerial>)getOfficematerialDAO().findByExample(officematerial);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Officematerial searchById(Integer officematerialId) {
		try {
			return getOfficematerialDAO().findById(officematerialId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Officematerial officematerial) {
		try {
			if(searchById(officematerial.getOfficematerialId()) != null) {
				getOfficematerialDAO().merge(officematerial);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerial> showAll() {
		try {
			return (List<Officematerial>)getOfficematerialDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
